package com.partsoft.dits.exts;

import java.util.Enumeration;
import java.util.NoSuchElementException;

public class CompoundEnumeration<T> implements Enumeration<T> {
	
	private Enumeration<T> enums[];
	private int index;

	public CompoundEnumeration(Enumeration<T> aenumeration[]) {
		index = 0;
		enums = aenumeration;
	}

	private boolean next() {
		for (; index < enums.length; index++) if (enums[index] != null && enums[index].hasMoreElements()) return true;
		return false;
	}

	public boolean hasMoreElements() {
		return next();
	}

	public T nextElement() {
		if (!next())
			throw new NoSuchElementException();
		else
			return enums[index].nextElement();
	}

}